#include "log.h"
#include "memorypool.h"
#include <boost/pool/pool.hpp>

// The shared boost memory pool.
static boost::pool<> _pool(sizeof(char));

MemoryPool::MemoryPool()
{

}

void *MemoryPool::alloc(size_t n)
{
    return _pool.ordered_malloc(n);
}

void MemoryPool::free(void *p, size_t n)
{
    if(!p || !n){
        LOG_ERROR() << "Invalid argument.";

        return;
    }

    if(!_pool.is_from(p)){
        LOG_ERROR() << "Memory leak: " << p << "(" << n << "byte(s))";

        return;
    }

    _pool.ordered_free(p, n);
}
